package com.freshminds.webservice;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.widget.Toast;

public class Utilities 
{
	 //Constants
	private static final String SOAP_ACTION = "http://fb.marqetrix.com/wss/GetAboutADSXML";
	 
	private static final String OPERATION_NAME = "GetAboutADSXML";
	 
	private static final String WSDL_TARGET_NAMESPACE = "http://fb.marqetrix.com/wss/";
	 
	private static final String SOAP_ADDRESS = "http://mobiapp.marqetrix.com/marqetrix.asmx";
	 
	
	Context context;
	public Utilities(Context context) 
	{
		this.context=context;
	}
	
	public void getAboutUsDetails()
	{
		Thread thread=new Thread(new Runnable() 
		{
			int i=0;//no exception occured
			SoapObject response;
			@Override
			public void run() 
			{
				try
				{
				SoapObject request=new SoapObject(WSDL_TARGET_NAMESPACE, OPERATION_NAME);
				SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		        envelope.setOutputSoapObject(request);
		        HttpTransportSE ht = new HttpTransportSE(SOAP_ADDRESS);
		        ht.call(SOAP_ACTION, envelope);
		        response = (SoapObject)envelope.bodyIn;
		        Object str = null;
		        for(int i=0;i<response.getPropertyCount();i++)
		        {
		        	str=response.getProperty(i);
		        }
		        
		        
		        for(int i=0;i<response.getPropertyCount();i++)
		        {
		        	str=response.getProperty(i);
		        }
		        
		        String str1 = str.toString();
		       
				}
				catch (Exception e) 
				{
					i=1;// exception occured
					
				}
		        finally
		        {
		        	Message message=new Message();
		        	message.what=i;
		        	if(response==null)
		        		message.obj="No Data ";
		        	else
		        		message.obj=response;
		        	
		        	
		        	handler.sendMessage(message);
		        }
				
			}
		});
		thread.start();
	}
	
	
	
	final Handler handler=new Handler()
	{

		@Override
		public void handleMessage(Message msg) 
		{
			if(msg.what==0)// called from get about us method
			{
				Toast.makeText(context, msg.obj.toString(), Toast.LENGTH_LONG);
			}
		}
		
	};
	
}
